package com.baidu.controller;

import com.baidu.constant.MyException;
import com.baidu.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;


/**
 * 捕获controller异常, 返回json
 * Restxxxxx就是返回json信息
 */
//@RestControllerAdvice
class MyExceptionAdvice {

    private static final Logger log = LoggerFactory.getLogger(MyExceptionAdvice.class);

    @ExceptionHandler(MyException.class)
    public Result handleMyExcepton(MyException e){
        log.info("进入了自定义异常处理，用户行为不规范");
        return new Result(false, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result handleExcepton(Exception e){
        log.error("发生未知异常了",e);
        return new Result(false, "发生未知异常，请联系管理员");
    }
}
